<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0">
  <title>我的 - 美食外卖平台</title>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
  <style>
    :root {
      --primary: #FF6B6B;
      --secondary: #FFE8E8;
      --text: #333;
      --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
      --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
      --radius-lg: 20px;
      --radius-md: 12px;
      --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
      --content-max-width: 1200px;
      --header-expanded: 220px;
      --header-compact: 60px;
    }

    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
      font-family: 'Helvetica Neue', system-ui;
    }

    body {
      background: #F8F9FA;
      color: var(--text);
      padding-bottom: 160px;
    }

    /* 头部系统 */
    .header {
      position: fixed;
      top: 0;
      width: 100%;
      height: var(--header-compact);
      background: white;
      box-shadow: var(--shadow-md);
      z-index: 1000;
      transition: all 0.4s ease;
    }

    .header.expanded {
      height: var(--header-expanded);
      background: linear-gradient(160deg, #FF6B6B 20%, #FF8E8E 100%);
    }

    /* 登录卡片 */
    .login-card {
      background: white;
      border-radius: var(--radius-lg);
      padding: 40px;
      box-shadow: var(--shadow-md);
      text-align: center;
      max-width: 500px;
      margin: 80px auto 40px;
    }

    .login-title {
      font-size: 28px;
      color: var(--primary);
      margin-bottom: 25px;
    }

    .login-desc {
      color: #666;
      line-height: 1.6;
      margin-bottom: 35px;
    }

    /* 模态框 */
    .modal {
      display: none;
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: rgba(0, 0, 0, 0.5);
      z-index: 2000;
    }

    .modal-content {
      background: white;
      width: 90%;
      max-width: 400px;
      padding: 30px;
      border-radius: var(--radius-md);
      position: relative;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }

    .close-btn {
      position: absolute;
      right: 20px;
      top: 20px;
      font-size: 24px;
      cursor: pointer;
    }

    .form-group {
      margin-bottom: 20px;
    }

    input {
      width: 100%;
      padding: 12px;
      border: 1px solid #ddd;
      border-radius: var(--radius-md);
      font-size: 16px;
      margin-top: 8px;
    }

    .modal-btn {
      background: var(--primary);
      color: white;
      width: 100%;
      padding: 16px;
      border: none;
      border-radius: var(--radius-md);
      cursor: pointer;
      font-size: 16px;
      transition: var(--transition);
    }

    .modal-btn:hover {
      opacity: 0.9;
    }

    /* 已登录内容 */
    .logged-in-content {
      display: none;
    }

    /* 原始页面样式 */
    .dynamic-title {
      position: fixed;
      top: -60px;
      left: 0;
      width: 100%;
      padding: 15px 20px;
      background: white;
      box-shadow: var(--shadow-sm);
      z-index: 1001;
      transition: top 0.3s var(--transition);
      display: flex;
      align-items: center;
      gap: 12px;
    }

    .dynamic-title.visible {
      top: 0;
    }

    .dynamic-title .icon {
      width: 32px;
      height: 32px;
      background: var(--secondary);
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--primary);
    }

    .main-content {
      padding: calc(var(--header-expanded) - 60px) 20px 120px;
      max-width: var(--content-max-width);
      margin: 0 auto;
      position: relative;
    }

    .profile-card {
      background: white;
      border-radius: var(--radius-lg);
      padding: 30px;
      box-shadow: var(--shadow-md);
      display: flex;
      align-items: center;
      gap: 25px;
      margin: 0 20px 40px;
      position: relative;
      top: -100px;
      z-index: 1001;
      transition: transform 0.4s var(--transition), opacity 0.3s ease;
    }

    .avatar {
      width: 120px;
      height: 120px;
      border-radius: 50%;
      object-fit: cover;
      border: 3px solid var(--primary);
      box-shadow: var(--shadow-sm);
    }

    .username {
      font-size: 28px;
      margin-bottom: 12px;
      color: var(--text);
      font-weight: 600;
    }

    .membership {
      background: var(--secondary);
      color: var(--primary);
      padding: 8px 20px;
      border-radius: 30px;
      display: inline-flex;
      align-items: center;
      gap: 10px;
      font-size: 15px;
      font-weight: 500;
    }

    .edit-btn {
      background: var(--primary);
      color: white;
      padding: 12px 30px;
      border-radius: 30px;
      border: none;
      cursor: pointer;
      transition: var(--transition);
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .function-grid {
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      gap: 25px;
      padding: 0 20px;
      margin-bottom: 50px;
    }

    .function-card {
      background: white;
      padding: 25px;
      border-radius: var(--radius-md);
      text-align: center;
      transition: var(--transition);
      box-shadow: var(--shadow-sm);
      cursor: pointer;
      position: relative;
      overflow: hidden;
    }

    .function-icon {
      font-size: 36px;
      color: var(--primary);
      margin-bottom: 20px;
    }

    .orders-section {
      padding: 0 20px;
      margin-top: 60px;
    }

    #orders-anchor {
      position: absolute;
      top: 400px;
    }

    .order-card {
      background: white;
      border-radius: var(--radius-md);
      padding: 25px;
      margin-bottom: 25px;
      box-shadow: var(--shadow-sm);
      transition: var(--transition);
    }

    .order-header {
      display: flex;
      justify-content: space-between;
      margin-bottom: 20px;
      align-items: center;
    }

    .order-status {
      color: var(--primary);
      font-weight: 6;
      padding: 6px 15px;
      border-radius: 20px;
      background: var(--secondary);
    }

    .order-detail {
      display: grid;
      grid-template-columns: 100px 1fr auto;
      gap: 20px;
      align-items: center;
    }

    .order-image {
      width: 100px;
      height: 100px;
      border-radius: var(--radius-md);
      object-fit: cover;
      border: 2px solid var(--secondary);
    }

    .order-price {
      font-size: 20px;
      color: var(--primary);
      font-weight: 700;
    }

    .bottom-nav {
      position: fixed;
      bottom: 0;
      width: 100%;
      background: white;
      display: flex;
      justify-content: space-around;
      padding: 15px 0;
      box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.08);
      z-index: 1002;
    }

    .nav-item {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 6px;
      color: #666;
      transition: var(--transition);
      text-decoration: none;
      font-size: 13px;
      padding: 10px;
      border-radius: 15px;
      width: 80px;
    }

    .nav-item.active {
      color: var(--primary);
      background: var(--secondary);
      transform: translateY(-8px);
    }

    /* 编辑模态框样式 */
    .edit-modal-content {
      background: white;
      width: 90%;
      max-width: 500px;
      padding: 30px;
      border-radius: var(--radius-md);
      position: relative;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }

    .avatar-upload {
      display: flex;
      flex-direction: column;
      align-items: center;
      margin-bottom: 20px;
    }

    .avatar-preview {
      width: 120px;
      height: 120px;
      border-radius: 50%;
      object-fit: cover;
      border: 3px solid var(--primary);
      margin-bottom: 15px;
      cursor: pointer;
    }

    .avatar-upload-btn {
      background: var(--secondary);
      color: var(--primary);
      padding: 8px 15px;
      border-radius: 20px;
      border: none;
      cursor: pointer;
      font-weight: 500;
    }

    @media (max-width: 768px) {
      :root {
        --header-expanded: 180px;
      }

      .profile-card {
        flex-direction: column;
        top: -80px;
      }

      .function-grid {
        grid-template-columns: repeat(2, 1fr);
      }

      .order-detail {
        grid-template-columns: 1fr;
      }
    }

    @media (max-width: 480px) {
      :root {
        --header-expanded: 160px;
      }

      .main-content {
        padding: calc(var(--header-expanded) - 40px) 15px 100px;
      }

      .function-grid {
        grid-template-columns: 1fr;
      }
    }
  </style>
</head>
<body>
<!-- 头部 -->
<header class="header"></header>

<!-- 动态标题 -->
<div class="dynamic-title" id="dynamicTitle">
  <div class="icon"><i class="fas fa-clipboard-list"></i></div>
  <h2>最近订单</h2>
</div>

<main class="main-content">
  <!-- 未登录状态 -->
  <div class="login-card" id="loginCard">
    <h2 class="login-title">欢迎来到美食世界</h2>
    <p class="login-desc">登录后可以查看个人资料、订单记录和管理收货地址</p>
    <button class="modal-btn" onclick="showLoginModal()">
      <i class="fas fa-sign-in-alt"></i>
      立即登录
    </button>
  </div>

  <!-- 已登录内容 -->
  <div class="logged-in-content" id="loggedInContent">
    <!-- 用户资料 -->
    <div class="profile-card">
      <img src="https://randomuser.me/api/portraits/women/85.jpg" class="avatar" alt="用户头像" id="userAvatar">
      <div class="profile-info">
        <h2 class="username" id="usernameDisplay">美食探险家</h2>
        <div class="membership">
          <i class="fas fa-crown"></i>
          VIP尊享会员
        </div>
      </div>
      <button class="edit-btn" onclick="showEditProfile()">
        <i class="fas fa-edit"></i>
        编辑资料
      </button>
    </div>

    <!-- 功能入口 -->
    <div class="function-grid">
      <div class="function-card">
        <i class="fas fa-clipboard-list function-icon"></i>
        <h3>我的订单</h3>
        <p>查看所有历史订单</p>
      </div>
      <div class="function-card">
        <i class="fas fa-tag function-icon"></i>
        <h3>优惠券</h3>
        <p>3张可用优惠券</p>
      </div>
      <div class="function-card">
        <i class="fas fa-map-marker-alt function-icon"></i>
        <h3>收货地址</h3>
        <p>管理配送地址</p>
      </div>
      <div class="function-card">
        <i class="fas fa-wallet function-icon"></i>
        <h3>我的钱包</h3>
        <p>余额：¥128.50</p>
      </div>
    </div>

    <!-- 订单锚点 -->
    <div id="orders-anchor"></div>

    <!-- 订单列表 -->
    <section class="orders-section">
      <div class="order-card">
        <div class="order-header">
          <div class="order-time">2023-08-01 18:45</div>
          <div class="order-status">配送完成</div>
        </div>
        <div class="order-detail">
          <img src="https://images.unsplash.com/photo-1552566626-52f8b828add9" class="order-image" alt="川味火锅">
          <div class="order-info">
            <h4>经典川味火锅套餐</h4>
            <p>麻辣牛油锅底 · 肥牛拼盘 · 蔬菜拼盘</p>
          </div>
          <div class="order-price">¥158</div>
        </div>
      </div>

      <div class="order-card">
        <div class="order-header">
          <div class="order-time">2023-07-30 12:15</div>
          <div class="order-status">已评价</div>
        </div>
        <div class="order-detail">
          <img src="https://images.unsplash.com/photo-1552566626-52f8b828add9" class="order-image" alt="寿司拼盘">
          <div class="order-info">
            <h4>日式寿司盛宴</h4>
            <p>刺身拼盘 · 手握寿司 · 味噌汤</p>
          </div>
          <div class="order-price">¥98</div>
        </div>
      </div>

      <div class="order-card">
        <div class="order-header">
          <div class="order-time">2023-07-30 12:15</div>
          <div class="order-status">已评价</div>
        </div>
        <div class="order-detail">
          <img src="https://images.unsplash.com/photo-1552566626-52f8b828add9" class="order-image" alt="寿司拼盘">
          <div class="order-info">
            <h4>日式寿司盛宴</h4>
            <p>刺身拼盘 · 手握寿司 · 味噌汤</p>
          </div>
          <div class="order-price">¥98</div>
        </div>
      </div>

      <div class="order-card">
        <div class="order-header">
          <div class="order-time">2023-07-30 12:15</div>
          <div class="order-status">已评价</div>
        </div>
        <div class="order-detail">
          <img src="https://images.unsplash.com/photo-1552566626-52f8b828add9" class="order-image" alt="寿司拼盘">
          <div class="order-info">
            <h4>日式寿司盛宴</h4>
            <p>刺身拼盘 · 手握寿司 · 味噌汤</p>
          </div>
          <div class="order-price">¥98</div>
        </div>
      </div>

      <div class="order-card">
        <div class="order-header">
          <div class="order-time">2023-07-30 12:15</div>
          <div class="order-status">已评价</div>
        </div>
        <div class="order-detail">
          <img src="https://images.unsplash.com/photo-1552566626-52f8b828add9" class="order-image" alt="寿司拼盘">
          <div class="order-info">
            <h4>日式寿司盛宴</h4>
            <p>刺身拼盘 · 手握寿司 · 味噌汤</p>
          </div>
          <div class="order-price">¥98</div>
        </div>
      </div>

      <div class="order-card">
        <div class="order-header">
          <div class="order-time">2023-07-30 12:15</div>
          <div class="order-status">已评价</div>
        </div>
        <div class="order-detail">
          <img src="https://images.unsplash.com/phone-1552566626-52f8b828add9" class="order-image" alt="寿司拼盘">
          <div class="order-info">
            <h4>日式寿司盛宴</h4>
            <p>刺身拼盘 · 手握寿司 · 味噌汤</p>
          </div>
          <div class="order-price">¥98</div>
        </div>
      </div>

      <div class="order-card">
        <div class="order-header">
          <div class="order-time">2023-07-30 12:15</div>
          <div class="order-status">已评价</div>
        </div>
        <div class="order-detail">
          <img src="https://images.unsplash.com/photo-1552566626-52f8b828add9" class="order-image" alt="寿司拼盘">
          <div class="order-info">
            <h4>日式寿司盛宴</h4>
            <p>刺身拼盘 · 手握寿司 · 味噌汤</p>
          </div>
          <div class="order-price">¥98</div>
        </div>
      </div>

      <div class="order-card">
        <div class="order-header">
          <div class="order-time">2023-07-30 12:15</div>
          <div class="order-status">已评价</div>
        </div>
        <div class="order-detail">
          <img src="https://images.unsplash.com/photo-1552566626-52f8b828add9" class="order-image" alt="寿司拼盘">
          <div class="order-info">
            <h4>日式寿司盛宴</h4>
            <p>刺身拼盘 · 手握寿司 · 味噌汤</p>
          </div>
          <div class="order-price">¥98</div>
        </div>
      </div>
    </section>
  </div>
</main>

<!-- 登录模态框 -->
<div id="loginModal" class="modal">
  <div class="modal-content">
    <span class="close-btn" onclick="closeLoginModal()">&times;</span>
    <h2 style="text-align: center; margin-bottom: 30px; color: var(--primary)">用户登录</h2>
    <form id="loginForm" onsubmit="handleLogin(event)">
      <div class="form-group">
        <input type="tel" id="phone" placeholder="请输入手机号" required>
      </div>
      <div class="form-group">
        <input type="password" id="password" placeholder="请输入密码" required>
      </div>
      <button type="submit" class="modal-btn">立即登录</button>
    </form>
  </div>
</div>

<!-- 编辑资料模态框 -->
<div id="editProfileModal" class="modal">
  <div class="edit-modal-content">
    <span class="close-btn" onclick="closeEditProfile()">&times;</span>
    <h2 style="text-align: center; margin-bottom: 30px; color: var(--primary)">编辑个人资料</h2>
    <form id="editProfileForm" onsubmit="handleProfileUpdate(event)">
      <div class="avatar-upload">
        <img src="https://randomuser.me/api/portraits/women/85.jpg" class="avatar-preview" id="avatarPreview"
             alt="头像预览">
        <button type="button" class="avatar-upload-btn" onclick="document.getElementById('avatarInput').click()">
          <i class="fas fa-camera"></i> 更换头像
        </button>
        <input type="file" id="avatarInput" accept="image/*" style="display: none" onchange="previewAvatar(event)">
      </div>

      <div class="form-group">
        <label for="editUsername">昵称</label>
        <input type="text" id="editUsername" placeholder="请输入昵称" required>
      </div>

      <div class="form-group">
        <label for="editPhone">手机号</label>
        <input type="tel" id="editPhone" placeholder="请输入手机号" required>
      </div>

      <div class="form-group">
        <label for="editEmail">电子邮箱</label>
        <input type="email" id="editEmail" placeholder="请输入电子邮箱">
      </div>

      <button type="submit" class="modal-btn">保存更改</button>
    </form>
  </div>
</div>

<!-- 底部导航 -->
<nav class="bottom-nav">
  <a href="ShoppingCentre.html" class="nav-item">
    <i class="fas fa-home"></i>
    <span>首页</span>
  </a>
  <a href="Found.html" class="nav-item">
    <i class="fas fa-search"></i>
    <span>发现</span>
  </a>
  <a href="ShoppingCart.html" class="nav-item">
    <i class="fas fa-shopping-cart"></i>
    <span>购物车</span>
  </a>
  <a href="#" class="nav-item active">
    <i class="fas fa-user"></i>
    <span>我的</span>
  </a>
</nav>
</body>
<script src="../js/jquery-3.7.1.js"></script>
<script>
  // 用户数据存储
  const userData = {
    username: "美食探险家",
    phone: "13812345678",
    email: "foodie@example.com",
    avatar: "https://randomuser.me/api/portraits/women/85.jpg",
    membership: "VIP尊享会员"
  };

  // 检查登录状态
  const checkAuth = () => !!sessionStorage.getItem('token');

  // 初始化页面
  function initPage() {
    const loginCard = document.getElementById('loginCard');
    const loggedInContent = document.getElementById('loggedInContent');
    const header = document.querySelector('.header');

    if (checkAuth()) {
      loginCard.style.display = 'none';
      loggedInContent.style.display = 'block';
      header.classList.add('expanded');
      loadUserData();
      initScrollEffect();
    } else {
      loginCard.style.display = 'block';
      loggedInContent.style.display = 'none';
      header.classList.remove('expanded');
    }
  }

  // 加载用户数据
  function loadUserData() {
    document.getElementById('usernameDisplay').textContent = userData.username;
    document.getElementById('userAvatar').src = userData.avatar;
    document.getElementById('editUsername').value = userData.username;
    document.getElementById('editPhone').value = userData.phone;
    document.getElementById('editEmail').value = userData.email;
    document.getElementById('avatarPreview').src = userData.avatar;
  }

  // 滚动效果
  function initScrollEffect() {
    const header = document.querySelector('.header');
    const dynamicTitle = document.getElementById('dynamicTitle');
    const ordersAnchor = document.getElementById('orders-anchor');

    window.addEventListener('scroll', () => {
      const scrollY = window.scrollY;
      const anchorTop = ordersAnchor.offsetTop - 100;

      if (scrollY > anchorTop) {
        header.classList.remove('expanded');
        dynamicTitle.classList.add('visible');
      } else {
        header.classList.add('expanded');
        dynamicTitle.classList.remove('visible');
      }
    });
  }

  // 显示登录模态框
  function showLoginModal() {
    document.getElementById('loginModal').style.display = 'block';
  }

  // 关闭登录模态框
  function closeLoginModal() {
    document.getElementById('loginModal').style.display = 'none';
  }

  // 处理登录
  function handleLogin(e) {
    e.preventDefault();
    const phone = document.getElementById('phone').value;
    const password = document.getElementById('password').value;
    $.ajax({
      method: 'POST',
      url: 'http://localhost:50729/login',
      contentType: "application/json",
      data:JSON.stringify({phone, password}),
      success: function (result) {
        console.log(result);
        if (result.code === 1) {
          sessionStorage.setItem("token",result.data)
          closeLoginModal();
          initPage();
        }else{
          alert(result.message);
        }
      }
    })
  }

  function RenderUserData() {

  }
  // 显示编辑资料模态框
  function showEditProfile() {
    document.getElementById('editProfileModal').style.display = 'block';
  }

  // 关闭编辑资料模态框
  function closeEditProfile() {
    document.getElementById('editProfileModal').style.display = 'none';
  }

  // 预览头像
  function previewAvatar(event) {
    const input = event.target;
    const preview = document.getElementById('avatarPreview');

    if (input.files && input.files[0]) {
      const reader = new FileReader();

      reader.onload = function (e) {
        preview.src = e.target.result;
      }

      reader.readAsDataURL(input.files[0]);
    }
  }

  // 处理资料更新
  function handleProfileUpdate(e) {
    e.preventDefault();

    // 获取表单数据
    const username = document.getElementById('editUsername').value;
    const phone = document.getElementById('editPhone').value;
    const email = document.getElementById('editEmail').value;
    const avatarInput = document.getElementById('avatarInput');

    // 更新用户数据
    userData.username = username;
    userData.phone = phone;
    userData.email = email;

    // 如果有新头像，更新头像
    if (avatarInput.files && avatarInput.files[0]) {
      const reader = new FileReader();
      reader.onload = function (e) {
        userData.avatar = e.target.result;
        document.getElementById('userAvatar').src = e.target.result;
      }
      reader.readAsDataURL(avatarInput.files[0]);
    }

    // 更新显示
    document.getElementById('usernameDisplay').textContent = username;

    // 关闭模态框
    closeEditProfile();

    // 这里可以添加API调用以保存更改
    // 例如: saveProfileData(userData);

    alert('个人资料已更新！');
  }

  // 初始化
  document.addEventListener('DOMContentLoaded', () => {
    initPage();

    // 点击模态框外部关闭
    window.onclick = function (event) {
      const loginModal = document.getElementById('loginModal');
      const editModal = document.getElementById('editProfileModal');

      if (event.target === loginModal) closeLoginModal();
      if (event.target === editModal) closeEditProfile();
    }
  });
</script>
</html>
